//
//  TestViewController.m
//  通讯录
//
//  Created by Mac OS on 15-11-9.
//  Copyright (c) 2015年 xiongmingkai. All rights reserved.
//

#import "TestViewController.h"
#import "ViewController.h"
@interface TestViewController ()
{
    UILabel * l;
    NSArray * date;
    NSArray * detail;
    NSArray * headers;
    
}
@end

@implementation TestViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    self.title = @"通讯录";
    self.view.backgroundColor = [UIColor whiteColor];
    l = [UILabel new];
    [l sizeToFit];
    l.center = CGPointMake(self.view.frame.size.width/2.0,self.view.frame.size.height/2.0);
    l.textColor = [UIColor redColor];
    date = @[
             @[@"安吧",@"安娜"],
             @[@"爸爸",@"白鸽"],
             @[@"曹操",@"曹植"],
             @[@"郭协",@"郭靖"],
             @[@"张三",@"朱元华"],
             ];
    detail = @[@"1",
               @"2",
               @"3",
               @"4",
               @"5",
               @"6",
               ];
    
    headers = @[@"A",
                @"B",
                @"C",
                @"G",
                @"Z",
                ];
    self.navigationItem.rightBarButtonItem=self.editButtonItem;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return date.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [date[section]count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.textLabel.text = date[indexPath.section][indexPath.row];
    //cell.detailTextLabel.text = detail[indexPath.row];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return headers [section];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ViewController * con = [ViewController new];
    [self.navigationController pushViewController:con animated:YES];
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPat5h //移动效果
{
    
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath  //删除内容
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSMutableArray * arr = date.mutableCopy;
        NSMutableArray * inarr = [date[indexPath.section]mutableCopy];
        [inarr removeObjectAtIndex:indexPath.row];
        [arr replaceObjectAtIndex:indexPath.section withObject:inarr];
        date = arr;
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
